<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!-- build:css /css/main.css -->
		<link href="/css/mui.css" rel="stylesheet" />
		<link href="/css/iconfont.css" rel="stylesheet" />
		<link href="/css/common.css" rel="stylesheet" />
		<!-- endbuild -->
		<!-- build:css /css/login-min.css -->
		<link href="/css/login.css" rel="stylesheet" />
		<!-- endbuild -->
	</head>

	<body>
		<header class="mui-bar mui-bar-nav u-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">忘记密码</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">

				<!-- <div class="mui-input-row">
					<label>
					<span class="mui-icon mui-icon-contact"></span>
				</label>
					<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入用户名"></div> -->

				<div class="mui-input-row">
					<label>
					<span class="mui-icon mui-icon-phone"></span>
				</label>
					<input id='tel' type="email" class="mui-input-clear mui-input" placeholder="请输入手机号码"></div>

				<div class="mui-input-row">
					<label>
					<span class="iconfont icon-yzm">
						<input type="text" placeholder="xxxx" />
					</span>
				</label>
					<input id='yzm' type="text" class="mui-input-clear mui-input" placeholder="请输入验证码">
					<div class="yzm-btn">获取验证码</div>
				</div>
				<div class="mui-input-row" id="err"></div>
			</form>
			<div class="mui-content-padded">
				<button id='send' class="mui-btn mui-btn-block mui-btn-danger">提交</button>
			</div>
		</div>
		<!-- build:js /js/vendor.js -->
		<script src="/js/mui.min.js"></script>
		<!-- bower:js -->
		<script src="/bower_components/mockjs/dist/mock.js"></script>
		<script src="/bower_components/zepto/zepto.js"></script>
		<script src="/bower_components/Zepto-Cookie/zepto.cookie.js"></script>
		<!--  endbower -->
		<!-- endbuild -->
		<!-- build:js /js/main.js -->
		<script src="/js/common.js"></script>
		<script src="/js/app.js"></script>
		<!-- endbuild -->
		<script>
			(function(mui, doc) {
				mui.init();
				var expiresDate = new Date();
				expiresDate.setTime(expiresDate.getTime() + (2 * 60 * 1000));
				mui.ready(function() {
					var settings = app.getSettings();
					var passwordBox = $('#regpassword');
					var regname = $('#regname');
					var emailBox = $('#email');
					var telBox = $('#tel');
					var yzmBox = $('#yzm');

					/*获取验证码*/
					var validCode = true;
					$('.yzm-btn').click(function(event) {
						var mobileVal = telBox.val();
						var time = 70;
						var that = $(this);
						if(!checkTel(mobileVal)) {
							$('#err').html('请输入正确的手机号！')
						} else {
							if(validCode) {
								$.ajax({
									url: __BATE__ + 'api/sendResetVerifyCode  ',
									type: 'post',
									data: {
										tel: mobileVal,
										code: codeVal
									},
									success: function(data) {

										$('#err').html(data.ret_msg)

									},
									error: function() {
										serverErr();
									}
								});
								validCode = false;
								var t = setInterval(function() {
									time--;
									that.html('获取验证码' + '(' + time + ')');
									if(time === 0) {
										clearInterval(t);
										that.html('重新获取');
										validCode = true;
									}
								}, 1000);
							}

						}
					});

					$('#send').on('tap', function(event) {
						var fogInfo = {
							tel: telBox.val(),
							yzm: yzmBox.val()
						};
						app.forgetPassword(fogInfo, function(err) {
							if(err) {
								$("#err").html(err);
								return false;
							}
							$.ajax({
								url: __BATE__ + 'api/resetRwCheck',
								type: 'post',
								data: {
									tel: telBox.val(),
									yzm: yzmBox.val(),
									code: codeVal
								},
								success: function(data) {
									if(data.ret_msg == '验证成功') {
										$.fn.cookie('token', json.token, {
											expires: expiresDate,
											path: '/'
										});
										mui.openWindow({
											url: '/user/setpassword.html',
											id: 'setpassword.html'
										});
									} else {
										$('#err').html(data.ret_msg);
									}

								}
							});

						});
					});
				});
			}(mui, document));
		</script>
	</body>

</html>